import {
	useUserStore
} from "../stores/useUserStore";

const vNormal = {
	mounted: (el, binding) => {
		const {
			value
		} = binding;

		const role = useUserStore().role;
		if (!["admin", "normal"].includes(role)) {
			el.style.display = 'none';
		}
	}
};

const vNormalOnly = {
	mounted: (el, binding) => {
		const {
			value
		} = binding;

		const role = useUserStore().role;
		if (role !== "normal") {
			el.style.display = 'none';
		}
	}
}

const vNotAdmin = {
	mounted: (el, binding) => {
		const {
			value
		} = binding;

		const role = useUserStore().role;
		if (role === "admin") {
			el.style.display = 'none';
		}
	}
}

const vAdmin = {
	mounted: (el, binding) => {
		const {
			value
		} = binding;

		const role = useUserStore().role;
		if (role !== "admin") {
			el.style.display = 'none';
		}
	}
}

export const auth = {
	install(app) {
		console.log("安装自定义指令");
		app.directive('normal', vNormal);
		app.directive('normalOnly', vNormalOnly);
		app.directive("admin", vAdmin);
		app.directive("notAdmin", vNotAdmin);
	}
}